﻿using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Framework.XSchEmA.Entity;

namespace Pixysoft.Framework.XSchEmA.testdriven
{
    class quickstart
    {
        /// <summary>
        /// 创建数据库
        /// </summary>
        public void test_001()
        {
            XSchemaManager.AccessSchema.Schema.CreateDatabase(null, AppDomain.CurrentDomain.BaseDirectory + "\\helloworld.mdb");
        }

        /// <summary>
        /// 创建表结构
        /// 少用，一般xml直接生成、或者从数据库直接获取表结构。
        /// </summary>
        public void test_002()
        {
            //初始化数据库链接信息
            DatabaseInfo info = new DatabaseInfo();
            info.Filename = AppDomain.CurrentDomain.BaseDirectory + "\\helloworld.mdb";
            info.DatabaseType = DatabaseType.Access;

            //手动初始化表结构
            DatabaseSchema db = new DatabaseSchema(info);
            TableSchema table = new TableSchema("HELLO");
            table.Columns.Add(new ColumnSchema("HELLO", "COLUMN1", new DataTypeSchema("TEXT")));
            db.Tables.Add(table);
            db.PrimaryKeys.Add(new PrimaryKeySchema("HELLO_PK", "HELLO", "COLUMN1"));
            db.Build();

            //部署
            XSchemaManager.AccessSchema.Schema.Commit(info, db);
        }

        /// <summary>
        /// 获取表结构
        /// </summary>
        public void test_003()
        {
            //初始化数据库链接信息
            DatabaseInfo info = new DatabaseInfo();
            info.Filename = AppDomain.CurrentDomain.BaseDirectory + "\\helloworld.mdb";
            info.DatabaseType = DatabaseType.Access;

            DatabaseSchema schema = XSchemaManager.AccessSchema.Schema.GetSchema(info);
            Console.WriteLine(schema.Tables[0].TableName);
        }
    }
}
